<? include ("../init.php") ?>
<?php
  if(!isset($_GET['aid'])){
    redirect('index.php');
    exit();
  }
  $product_id = $_GET['aid'];
  
  $sql = "SELECT * FROM products WHERE product_id = '".$product_id."'";
  $line = $db->queryUniqueObject($sql);
  if($line->product_title==''){
    redirect('index.php');
    exit();
  }
  
  function get_product_setname($product_set_id){
    $db2 = new DB(DB_NAME, DB_SERVER, DB_USER, DB_PWD);
    $db2->charset(DB_CHARSET);
    $sql = 'SELECT * FROM product_set WHERE product_set_id='.$product_set_id;
    $line = $db2->queryUniqueObject($sql);
    return $line->product_set_name;
  }
?>
<? include ("../header.php") ?>
<? include ("../menu.php") ?>
<? include ("submenu.php") ?>

<div id = "body">

<h1><?php //echo get_product_setname($product_set_id); ?> : <?_l('edit')?><?_l('product')?></h1>
<div class = "clear"></div>


<form method="post" action="update_product.php" class = "form" enctype="multipart/form-data">
  <input type="hidden" name="product_set_id" value="<?php echo $line->product_set_id; ?>" />
  <input type="hidden" name="product_id" value="<?php echo $line->product_id; ?>" />
  <input type="hidden" name="old_img" value="<?php echo $line->product_img; ?>" />
  <input type="hidden" name="old_img_2" value="<?php echo $line->product_img_2; ?>" />
  <input type="hidden" name="old_img_3" value="<?php echo $line->product_img_3; ?>" />
  <input type="hidden" name="old_img_4" value="<?php echo $line->product_img_4; ?>" />
  <div class = "field"><label><?_l('product-name')?></label><input value="<?php echo $line->product_title; ?>" type = "text" name = "name" class = "input size1" ></div>
  <div class = "field"><label><?_l('overall-width')?></label><input value="<?php echo $line->product_width; ?>" type = "text" name = "width" class = "input size1" ></div>
  <div class = "field"><label><?_l('overall-depth')?></label><input value="<?php echo $line->product_depth; ?>" type = "text" name = "depth" class = "input size1" ></div>
  <div class = "field"><label><?_l('height')?></label><input value="<?php echo $line->product_height; ?>" type = "text" name = "height" class = "input size1" ></div>
  <div class = "field"><label><?_l('material')?></label><input value="<?php echo $line->product_material; ?>" type = "text" name = "material" class = "input size2" ></div>
  <div class = "field"><label><?_l('detail')?></label><textarea name="detail"><?php echo $line->product_detail; ?></textarea></div>
  
  <div class = "field"><label><?_l('image')?></label><input type = "file" name = "img" class = "input size2" ></div>
  <?php
    if($line->product_img!='' && file_exists('../../images/products/'.$product_id.'/'.$line->product_img)){
      echo '<div class = "field"><label>&nbsp;</label><img src="../../images/products/'.$product_id.'/'.$line->product_img.'" /></div>';
    }
  ?>
  
  <div class = "field"><label><?_l('thumb')?>1</label><input type = "file" name = "img1" class = "input size2" ></div>
  <?php
    if($line->product_img_2!='' && file_exists('../../images/products/'.$product_id.'/'.$line->product_img_2)){
      echo '<div class = "field"><label>&nbsp;</label><img src="../../images/products/'.$product_id.'/'.$line->product_img_2.'" /></div>';
    }
  ?>
  
  <div class = "field"><label><?_l('thumb')?>2</label><input type = "file" name = "img2" class = "input size2" ></div>
  <?php
    if($line->product_img_3!='' && file_exists('../../images/products/'.$product_id.'/'.$line->product_img_3)){
      echo '<div class = "field"><label>&nbsp;</label><img src="../../images/products/'.$product_id.'/'.$line->product_img_3.'" /></div>';
    }
  ?>
  
  <div class = "field"><label><?_l('thumb')?>3</label><input type = "file" name = "img3" class = "input size2" ></div>
  <?php
    if($line->product_img_4!='' && file_exists('../../images/products/'.$product_id.'/'.$line->product_img_4)){
      echo '<div class = "field"><label>&nbsp;</label><img src="../../images/products/'.$product_id.'/'.$line->product_img_4.'" /></div>';
    }
  ?>
  
  <hr>
  <div class = "field"><label></label><input type = "submit" value = "<?=__l('update')?>" class = "btn">&nbsp;<a href = "#" class = "btn" onclick="javascript:history.back(1)"><?_l('cancel')?></a></div>
</form>

</div>

<style>
  .form label {
    width:80px;
  }
</style>
</div>
<? include "../footer.php" ?>